import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

/**
 * UI class mapping an Image to a window
 *
 */
public class ImageViewerPanel extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int[][] _matrix;
	
	public ImageViewerPanel(int[][] matrix) {
		setBackground(Color.white);
		setPreferredSize(new Dimension(ImageViewer.WINDOW_WIDTH, ImageViewer.WINDOW_HEIGHT));
		_matrix = matrix;
		repaint();
	}
	
	public static Color grayValueToColor(int value) {
		int realValue = 31 - value;
		return new Color(8*realValue, 8*realValue, 8*realValue);
	}
	
	public void paint(Graphics g) {
		super.paint(g);
		int square_height = ImageViewer.WINDOW_HEIGHT / Image.IMAGE_HEIGHT;
		int square_width = ImageViewer.WINDOW_WIDTH / Image.IMAGE_WIDTH;
		for (int i = 0; i < Image.IMAGE_WIDTH; i++) {
			for (int j = 0; j < Image.IMAGE_HEIGHT; j++) {
				g.setColor(grayValueToColor(_matrix[i][j]));
				g.fillRect(i*square_width, j*square_height, square_width, square_height);
			}
		}
	}
	
	
}
